package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.common.TreeResult;
import com.taotao.mapper.TbItemCatMapper;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.pojo.TbItemCatExample.Criteria;
import com.taotao.service.ItemCatService;
@Service
public class ItemCatServiceImpl implements ItemCatService{
	
	@Autowired
	private TbItemCatMapper itemCatMapper;
	
	@Override
	public List<TreeResult> getItemCatList(long cid) {
		List<TreeResult> list=new ArrayList<>();
		TbItemCatExample itemCat=new TbItemCatExample();
		Criteria criteria = itemCat.createCriteria();
		criteria.andParentIdEqualTo(cid);
		List<TbItemCat> selectByExample = itemCatMapper.selectByExample(itemCat);
		for(TbItemCat itemCats:selectByExample){
			TreeResult treeResult=new TreeResult();
			treeResult.setId(itemCats.getId());
			treeResult.setText(itemCats.getName());
			treeResult.setState(itemCats.getIsParent()?"closed":"open");
			list.add(treeResult);
		}
		return list;
	}

}
